package com.wx.app.spacewhisper.service.impl;

import com.wx.app.spacewhisper.entity.Whisper;
import com.wx.app.spacewhisper.mapper.WhisperMapper;
import com.wx.app.spacewhisper.service.WhisperService;
import com.wx.app.spacewhisper.utils.token.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestHeader;


import java.util.Date;


@Service
public class WhisperServiceImpl implements WhisperService {

    @Autowired
    WhisperMapper whisperMapper;

    @Override
    public int insertWhisper(String content, @RequestHeader("token") String token){
        TokenUtils tokenUtils=new TokenUtils();
        int id=tokenUtils.parseId(token);

        Integer state=0;
        Date date=new Date();
        Long dateTime=System.currentTimeMillis();
        return whisperMapper.insertWhisper(content,dateTime,state);
    }

    @Override
    public Whisper selectWhisperById(Integer id){
        return whisperMapper.selectWhisper(id);
    }

}
